package com.warom.sdg.repository;

import android.app.Application;
import android.util.Log;

import com.warom.sdg.dao.ThresholdSettingDao;
import com.warom.sdg.database.SdgDatabase;
import com.warom.sdg.model.ThresholdSettingEntity;

import java.util.List;

/**
 * 阈值设置仓库类
 * 负责阈值设置数据的业务逻辑
 */
public class ThresholdSettingRepository {
    private static final String TAG = "ThresholdSettingRepo";
    private final ThresholdSettingDao thresholdSettingDao;

    public ThresholdSettingRepository(Application application) {
        SdgDatabase database = SdgDatabase.getInstance(application);
        this.thresholdSettingDao = database.getThresholdSettingDao();
    }

    /**
     * 获取所有阈值设置
     * @return 阈值设置列表
     */
    public List<ThresholdSettingEntity> getAllThresholdSettings() {
        return thresholdSettingDao.getAll();
    }

    /**
     * 根据参数类型获取阈值设置
     * @param paramType 参数类型
     * @return 阈值设置
     */
    public ThresholdSettingEntity getThresholdSettingByParamType(String paramType) {
        return thresholdSettingDao.getByParamType(paramType);
    }

    /**
     * 保存阈值设置
     * @param entity 阈值设置实体
     * @return 是否保存成功
     */
    public boolean saveThresholdSetting(ThresholdSettingEntity entity) {
        try {
            return thresholdSettingDao.upsert(entity);
        } catch (Exception e) {
            Log.e(TAG, "保存阈值设置失败", e);
            return false;
        }
    }
} 